package com.gdgk.shop.api.config;

import lombok.Data;
import org.apache.commons.io.IOUtils;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.Resource;
@Data
@Component
@ConfigurationProperties(prefix = "wx.pay")
public class WxPayProperties {
    /**
     * 设置微信公众号或者小程序等的appid
     */
    private String appId;

    /**
     * 微信支付商户号
     */
    private String mchId;

    /**
     * 微信支付APIV3密钥
     */
    private String apiV3Key;

    /**
     * apiclient_cert.p12文件的绝对路径，或者如果放在项目中，请以classpath:开头指定
     */
    private String keyPath;

    /**
     * 证书序列号
     */
    private String serial;

    @Value("classpath:wxpay/apiclient_key.pem")
    private Resource resource;

    public String getPrivateKey() throws IOException {
        InputStream inputStream = this.resource.getInputStream();
        return IOUtils.toString(inputStream, StandardCharsets.UTF_8);
    }

}

